package com.anpxd.erpad.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lsxiao.apollo.core.Apollo
import com.lsxiao.apollo.core.contract.ApolloBinder
import com.trello.rxlifecycle2.components.support.RxFragment

/**
 * Creator : GG
 * Time    : 2017/10/29
 * Mail    : gg.jin.yu@gmail.com
 * Explain :
 */
abstract class BaseFragment : RxFragment() {


    var rootView: View? = null
    private var mBinder: ApolloBinder? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView = inflater.inflate(getLayoutResId(), container, false)
        return rootView
    }

    abstract fun getLayoutResId(): Int


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        if (useBus())
            mBinder = Apollo.bind(this)
    }

    open fun useBus(): Boolean = false

    override fun onDestroyView() {
        super.onDestroyView()
        if (useBus() && null != mBinder) {
            mBinder!!.unbind()
        }
    }

}